#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 510, M = 13;

/*
since 

*/

int n, m;
int g[N][N];
vector<int> fodd[M], feven[M];
bool f1[M], f2[M];   // f1: odd , f2: even

void f(){
    for(int i = 0; i < M; i ++){
        f1[i] = f2[i] = false;
    }
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);


    cin >> n >> m;

    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= m; j ++){
            cin >> g[i][j];
        }
    }

    f();

    for(int i = 1; i <= m; i ++){
        for(int j = 0; j < M; j ++){
            
            if(!f1[j] && (g[1][i] >> j & 1)){
                f1[j] = true;
                fodd[j].push_back(i);
            }

            if(!f2[j] && ((g[1][i] >> j & 1) == 0)){
                f2[j] = true;
                feven[j].push_back(i);
            }

        }
    }   


    for(int i = 2; i <= n; i ++){
        f();        
        vector<int> tfodd[M], tfeven[M];
        for(int j = 1; j <= m; j ++){
            for(int p = 0; p < M; p ++){
                if(!f1[p] && (g[i][j] >> p & 1) && !feven[p].empty()){
                    tfodd[p] = feven[p];
                    tfodd[p].push_back(j);
                    f1[p] = true;
                }

                if(!f1[p] && (g[i][j] >> p & 1) == 0 && !fodd[p].empty()){
                    tfodd[p] = fodd[p];
                    tfodd[p].push_back(j);
                    f1[p] = true;
                }

                if(!f2[p] && (g[i][j] >> p & 1) && !fodd[p].empty()){
                    tfeven[p] = fodd[p];
                    tfeven[p].push_back(j);
                    f2[p] = true;
                }

                if(!f2[p] && (g[i][j] >> p & 1) == 0 && !feven[p].empty()){
                    tfeven[p] = feven[p];
                    tfeven[p].push_back(j);
                    f2[p] = true;   
                }

          //      cout << tfodd[p].size() << '\n';
            }
        }

        for(int j = 0; j < M; j ++){
            fodd[j] = tfodd[j];
            feven[j] = tfeven[j];
        }

    }

    bool ok = false;
    vector<int> ans;
    for(int i = 0; i < M; i ++){
        if(!fodd[i].empty()){
            ok = true;
            for(int j = 0; j < fodd[i].size(); j ++){
                ans.push_back(fodd[i][j]);
            }
            break;
        }
    }

    if(ok){
        cout << "TAK" << '\n';
        for(int i = 0; i < ans.size(); i ++){
            cout << ans[i] << " ";
        }
    }else{
        cout << "NIE" << '\n';
    }



    return 0;
}